home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / fract / FlashMandel.lha / FlashMandel / Sources / Modules / MandInt.S < prev    next >
Text File  |  1999-01-22  |  4KB  |  173 lines

  1.  
  2. ********************************************************************************
  3. **
  4. **  Original code made by Tobias Ferber and Martin Giese (Mandel-92)
  5. **
  6. **  Rewritten and speeded up by Dino Papararo            01-Mar-1997
  7. **
  8. **  FUNCTION
  9. **
  10. **    MandInt -- perform Z = Z^2 + C iteration.
  11. **
  12. **  SYNOPSIS
  13. **
  14. **    WORD MandINT (WORD Iterations,LONG Cre,LONG Cim)
  15. **
  16. **
  17. **  DESCRIPTION
  18. **
  19. **    Work with fixed-point real numbers, x between -8 and 8 (aprox.)
  20. **    being represented by x*2^(28) in a long.
  21. **
  22. **
  23. **    MandInt performs an iteration given by
  24. **
  25. **                             2    2
  26. **    x = r    y = i    x   = x  - y  + r    y   = 2 x  y + i
  27. **     0        0        j+1   j    j         j+1     j  j
  28. **
  29. **
  30. **    2 x y  is calculated via
  31. **
  32. **
  33. **                   2    2    2
  34. **    2 x y = (x + y)  - x  - y
  35. **
  36. **
  37. **    as the squaring of x+y requires only three more multiplicaitons vs.
  38. **    four for a normal multiplication of longs.
  39. **
  40. **    the iterations is performed up to n times, but may stop before that
  41. **    if x^2+y^2 exceeds 2.00
  42. **
  43. **    The value returned is the number of iterations actually done.
  44. **
  45. ********************************************************************************
  46.  
  47. ***** d0:Iterations d1:zr d2:zi d3:Quad d4:zr2 d5:zi2 d6:Const d7:Const ********
  48.  
  49. ******************************** a0:Cre a1:Cim *********************************
  50.  
  51. ********************************************************************************
  52.  
  53.  
  54.         XDEF  _MandINT
  55.  
  56. _MandINT:
  57.  
  58.         movem.l d3-d7,-(sp)     ; save regs
  59.  
  60.  
  61.         move.l  d1,a0           ; a0 = Cre
  62.         move.l  d2,a1           ; a1 = Cim
  63.         moveq.l #12,d6          ; d6 = 12
  64.         moveq.l #11,d7          ; d7 = 11
  65.  
  66.  
  67. Iter:
  68.         move.l  d1,d3           ; save zr in d3 & calculate zr^2
  69.         bpl.s   Positiv_1
  70.         neg.l   d1
  71.  
  72. Positiv_1:
  73.  
  74.         move.w  d1,d4           ; d4   = Rl
  75.         mulu.w  d4,d4           ; d4   = Rl * Rl
  76.         clr.w   d4              ; d4.w = 0
  77.         swap.w  d4              ; d4   = d4 >> 16
  78.         lsr.w   d6,d4           ; d4   = d4 >> 12
  79.  
  80.         move.w  d1,d5           ; d5   = Rl
  81.         swap.w  d1              ; d1.w = Rh
  82.         mulu.w  d1,d5           ; d5   = Rh * Rl
  83.         lsr.l   d7,d5           ; d5   = d7 >> 11
  84.  
  85.         add.l   d5,d4           ; d4   = ((Rl * Rl) >> 28) + ((2 * Rl * Rh) >> 12)
  86.  
  87.         mulu.w  d1,d1           ; d1   = Rh * Rh
  88.         asl.l   #4,d1           ; d1   = d4 << 4
  89.         bvs.s   Exit            ; Check Overflow
  90.         
  91.         add.l   d2,d3           ; add zi in d3 & calculate zi^2
  92.  
  93.         add.l   d1,d4           ; d4 = d4 + ((Rh * Rh) << 4)
  94.                                 ; zr * zr
  95.  
  96.  
  97.         tst.l   d2
  98.         bpl.s   Positiv_2
  99.         neg.l   d2
  100.  
  101. Positiv_2:
  102.  
  103.         move.w  d2,d5
  104.         mulu.w  d5,d5
  105.         clr.w   d5
  106.         swap.w  d5
  107.         lsr.w   d6,d5
  108.  
  109.         move.w  d2,d1
  110.         swap.w  d2
  111.         mulu.w  d2,d1
  112.         lsr.l   d7,d1
  113.  
  114.         add.l   d1,d5
  115.  
  116.         mulu.w  d2,d2
  117.         asl.l   #4,d2
  118.         bvs.s   Exit
  119.         
  120.         move.l  d4,d1
  121.  
  122.         add.l   d2,d5           ; d5 = zi * zi
  123.         add.l   d5,d1           ; zr2 + zi2
  124.         bvs.s   Exit            ; if overflow exit
  125.         cmpi.l  #$40000000,d1   ; compare (zr2 + zi2) with (4 * 2^28)
  126.         bgt.s   Exit            ; if greater exit
  127.  
  128.  
  129.  
  130.         tst.l   d3              ; calculate (zi + zr)^2
  131.         bpl.s   Positiv_3
  132.         neg.l   d3
  133.  
  134. Positiv_3:
  135.  
  136.         move.w  d3,d2
  137.         mulu.w  d2,d2
  138.         clr.w   d2
  139.         swap.w  d2
  140.         lsr.w   d6,d2
  141.  
  142.         move.w  d3,d1
  143.         swap.w  d3
  144.         mulu.w  d3,d1
  145.         lsr.l   d7,d1
  146.  
  147.         add.l   d1,d2
  148.  
  149.         mulu.w  d3,d3
  150.         asl.l   #4,d3
  151.         bvs.s   Exit
  152.         add.l   d3,d2           ; d5 = (zi + zr)^2
  153.  
  154.  
  155.  
  156.         move.l  a0,d1           ; d1  = Cre
  157.         move.l  a1,d3           ; d3  = Cim
  158.         sub.l   d4,d2           ; d2  = (zr + zi)^2 - zr2
  159.         sub.l   d5,d1           ; d1 -= zi2
  160.         add.l   d3,d2           ; d2 += Cim
  161.         add.l   d4,d1           ; d1 += zr2
  162.         sub.l   d5,d2           ; d2 -= zi2
  163.  
  164.         dbra.w  d0,Iter         ; if Iterations != 0) go to Iter
  165.         moveq.l #0,d0           ; else Iterations = 0
  166.  
  167. Exit:
  168.         movem.l (sp)+,d3-d7     ; restore regs
  169.  
  170.         rts                     ; return Iterations
  171.  
  172.         end                     ; end.
  173.